#!/usr/bin/env bash

read -p "Input:" -s option
echo $option

echo "=================================================="

read -p "Input: " option <<!
xxx
!
echo $option

read -p "Input2: " option2
if [ ! -z "$option2" ]
then
    echo $option2
else
    echo "null"
fi

echo "=================================================="

echo "\
aaa bbb
ccc
ddd" >file.txt

# 会导致while成为一个子进程，用到的变量无法被父进程使用
# 不可用
cat file.txt | while read line
do
    echo $line
done
echo "--------------------------------------------------"

# 以空格为间隔，并非行
# 必须更改IFS
IFS_BAK=$IFS
IFS="\n"
#for line in $(cat file.txt)
for line in $(<file.txt)
do
    echo $line
done
IFS=$IFS_BAK;

for line in $(<file.txt)
do
    echo $line
done
echo "--------------------------------------------------"

# 正确
while read line
do
    echo $line
done <file.txt

echo "=================================================="
